package com.amox.uitest.tcase;

import com.amox.uitest.kit.LogKit;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

import android.os.Bundle;
import ognl.OgnlContext;

public abstract class BaseTestCase extends UiAutomatorTestCase {
	
	public static OgnlContext context = new OgnlContext();

	public Bundle bundle = null;
	
	public Object before() {
		LogKit.printLog("STARTING !");
		bundle = getParams();// getParams
		initContext(bundle);
		return null;
	}
	
	
	public void initContext(Bundle bundle) {
		for(String key :bundle.keySet()) {
			BaseTestCase.context.put(key, bundle.getString(key));
		}
	}
	
	/**
	 * abstract method
	 * uiautomator runtest amox-uitest.jar -c com.amox.uitest.Rocket#lauch
	 * @throws Exception
	 */
	public abstract void play() throws Exception;
	
	public Object after() {
		BaseTestCase.context.clear();
		LogKit.printLog("FINISHED !");
		return null;
	}
	
	public void lauch() {
		try {
			before();
			play();
		} catch (Exception e) {
			LogKit.printLog("ERROR : The Program Is Interrupted !");
			e.printStackTrace();
		} finally {
			after();
		}
	}
}
